<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <form id="userForm">
        <div>
            <label for="bookname">名称</label><input type="text" name="bookname" id="bookname">
        </div>
        <div>
            <label for="author">作者</label><input type="text" name="author" id="author">
        </div>
        <div>
            <label for="publisher">出版社</label><input type="text" name="publisher" id="publisher">
        </div>
        <div>
            <input type="submit" value="提交">
        </div>

    </form>
    <script src="../jquery-1.12.4.js"></script>
    <script>
        $(function() {
            $('#userForm').submit(function(e) {
                e.preventDefault();
                var bookname = $('#bookname').val();
                var author = $('#author').val();
                var publisher = $('#publisher').val();
                var formData = $(this).serialize();
                $.post('http://www.liulongbin.top:3006/api/addbook', {
                        bookname: bookname,
                        author: author,
                        publisher: publisher
                    }, function(res) {
                        console.log(res)
                    })
                    //     $.post('http://www.liulongbin.top:3006/api/addbook',
                    //         formData,
                    //         function(res) {
                    //             console.log(res);
                    //         })
            })
        })
    </script>
</body>

</html>